package com.tarena.lbs.coupon.rpc;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.coupon.api.CouponApi;
import com.tarena.lbs.coupon.api.pojo.param.UserCouponsParam;
import com.tarena.lbs.coupon.service.CouponService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: goodman
 * @Date: 2025/5/15 17:31
 */

@Slf4j
@Component
@DubboService
public class CouponApiImpl implements CouponApi {

    @Autowired
    private CouponService couponService;

    @Override
    public void receiveCoupon(UserCouponsParam param) throws BusinessException {
        log.info("=== CouponApiImpl.receiveCoupon 开始 ===");
        log.info("远程API领取优惠券，入参：{}", param);
        
        try {
            // 调用CouponService的receiveCoupon方法
            couponService.receiveCoupon(param);
            log.info("远程API领取优惠券成功，入参：{}", param);
            log.info("=== CouponApiImpl.receiveCoupon 结束 ===");
        } catch (Exception e) {
            log.error("远程API领取优惠券失败：{}", e.getMessage(), e);
            throw e;
        }
    }

}
